package com.zhsj.OkeHomeConsumption.ui.activity.bussiness;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.hjq.bar.TitleBar;
import com.orhanobut.hawk.Hawk;
import com.zhsj.OkeHomeConsumption.R;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.MyActivity;
import com.zhsj.OkeHomeConsumption.common.OkeHomeConsumptionApi;
import com.zhsj.OkeHomeConsumption.empty.FormalUserInfo;
import com.zhsj.OkeHomeConsumption.other.QRCodeUtil;
import com.zhsj.OkeHomeConsumption.ui.activity.bussiness.mvp.ReceiptQRcodePresenter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 商家页面---邀请二维码
 */

public class InviteQRcodeActivity extends MyActivity {

    @BindView(R.id.tb_copy_title)
    TitleBar tbCopyTitle;
    private ImageView qr_code = null;

    private ReceiptQRcodePresenter minePersonPresenter;

    private FormalUserInfo userinfo = null;

    private int flage = -1; //1 商家  2 会员

    private String web_url;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_receiptqrcode;
    }

    @Override
    protected int getTitleId() {
        return R.id.tb_copy_title;
    }

    @Override
    protected void initView() {
        Intent intent = getIntent();
        flage = intent.getIntExtra("flage", -1);
        qr_code = findViewById(R.id.qr_code);
        tbCopyTitle.setTitle("邀请二维码");


    }

    @Override
    protected void initData() {
        userinfo = Hawk.get(Constants.SHARED_PERFERENCE_USERINFO);
        switch (flage) {
            case 1:
                web_url = OkeHomeConsumptionApi.ELVDOU_BASEURL_H5_LIFE + "app/h5/platform/12.html?userid=" + userinfo.getId();
                break;
            case 2:
                web_url = OkeHomeConsumptionApi.ELVDOU_BASEURL_H5 + "app/h5/platform/12.html?userid="+userinfo.getId()+ "&invite=" + userinfo.getId()+"&type=1&rtype=1";
                break;


        }
        Bitmap bitmap = QRCodeUtil.createQRImage(web_url);
        Glide.with(getActivity()).load(bitmap).placeholder(R.drawable.zhanweitu_bg).into(qr_code);


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
